<!DOCTYPE html>
<html lang="zn">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="../js/vue.js"></script>
  <title>更新时的一个问题</title>
  <style>
    button {
      margin-bottom: 20px;
    }
  </style>
</head>

<body>
  <div id="root">
    <!-- 遍历数组 -->
    <h2>人员列表(遍历数组)</h2>
    <button @click="changeFirst">更新第一个数据的性别</button>
    <ul>
      <li v-for="(person,index) in personList" :key="index">
        {{person.name}}-{{person.age}}-{{person.sex}}
      </li>
    </ul>
  </div>

  <script>
    Vue.config.productionTip = false
    // 计算属性实现
    const vm =  new Vue({
      el: '#root',
      data() {
        return {
          personList: [
            { id: '001', name: '张三', age: 26, sex: '男' },
            { id: '002', name: '李四', age: 25, sex: '男' },
            { id: '003', name: '王五', age: 17, sex: '女' },
            { id: '004', name: '老王', age: 16, sex: '女' },
            { id: '005', name: '王三', age: 50, sex: '女' },
          ]
        }
      },
      methods: {
        changeFirst() {
          /*
          this.personList[0].name = '马保国' //奏效
          this.personList[0].age = 50//奏效
          this.personList[0].sex = '男'//奏效
          */
         this.personList[0] = {id:'001',name:'马保国',age:50,sex:'男'}
         console.log('数据更新了')
        }
      },
    })
  </script>
</body>

</html>